const glob = require('glob')
const path = require('path')

let controllers = {}
glob.sync(path.resolve(__dirname, './', '**/*.js'))
  .filter(value => (value.indexOf('controller/index.js') === -1))
  .forEach(controllerPath => {
    // 获取模块名称
    let moudlePath = path.resolve(controllerPath, '..')
    let moudleName = path.basename(moudlePath)
    
    // 获取不带后缀的文件名
    let baseName = path.basename(controllerPath)
    let key = baseName.substring(0, baseName.lastIndexOf('.'))
    controllers[`${moudleName}.${key}`] = require(controllerPath)
  })

module.exports = controllers